package com.ipharma.dto;

import java.sql.*;

import com.ipharma.McdError;
import com.ipharma.McdPrs;

/**
 * A Task class.
 * <P>
 * 
 * @author JorgE.H
 */
public class Task {

   /**
    * Attributes
    */
   protected boolean done = false;

   protected String description = "";

   protected String code = "";

   protected String origin = "";

   protected int batchNumber;

   protected int prodId;

   protected int taskId;

   protected int quantity;

   /**
    * Constructor
    */
   public Task() {

   }

   /**
    * Constructor
    * 
    * @param pDesc
    *           product description
    * @param pCode
    *           product code
    * @param pProdId
    *           product id
    * @param pBatchNumber
    *           product batch number
    * @param pQuantity
    *           recharging quantity
    * @param pOrigin
    *           source of recharging products
    * @param pDone
    *           boolean task done
    */
   public Task(String pDesc, String pCode, int pProdId, int pTaskId,
         int pBatchNumber, int pQuantity, String pOrigin, boolean pDone) {

      done = pDone;
      description = pDesc;
      code = pCode;
      batchNumber = pBatchNumber;
      origin = pOrigin;
      prodId = pProdId;
      taskId = pTaskId;
      quantity = pQuantity;
   }

   /**
    * Constructor
    * 
    * @param pDesc
    *           product description
    * @param pCode
    *           product code
    * @param pProdId
    *           product id
    * @param pBatchNumber
    *           product batch number
    * @param pQuantity
    *           recharging quantity
    * @param pOrigin
    *           source of recharging products
    * @param pDone
    *           boolean task done
    */
   public Task(ResultSet pRs) {

      try {
         String ls_done = pRs.getString("tsk_ok");
         if (ls_done != null)
            done = ls_done.toUpperCase().equals(McdPrs.D_YES);

         description = pRs.getString("pdt_description");
         code = pRs.getString("pdt_code");
         origin = pRs.getString("tsk_source");
         batchNumber = pRs.getInt("batch_number");
         prodId = pRs.getInt("pdt_id");
         taskId = pRs.getInt("tsk_id");
         quantity = pRs.getInt("tsk_quantity");
      } catch (Exception e) {
         McdError.add(e);
      }
   }

   /**
    * Returns task completition
    * 
    * @returns true if it is completed, false otherwise
    */
   public boolean isDone() {

      return done;
   }

   /**
    * Changes task completion status
    * 
    * @param pDone
    *           new boolean state
    */
   public void setDone(boolean pDone) {

      done = pDone;
   }

   /**
    * Returns done status
    * 
    * @return String done status
    */
   public String getDone() {

      return done ? McdPrs.D_YES : McdPrs.D_NO;
   }

   /**
    * Returns product code
    * 
    * @returns String code
    */
   public String getCode() {

      return code;
   }

   /**
    * Returns product batch number
    * 
    * @returns String batch number
    */
   public int getBatchNumber() {

      return batchNumber;
   }

   /**
    * Changes product batch number
    * 
    * @param pBatch
    *           String batch number
    */
   public void setBatch(int pBatch) {

      batchNumber = pBatch;
   }

   /**
    * Returns product description
    * 
    * @returns String description
    */
   public String getDescription() {

      return description;
   }

   /**
    * Returns recharging product origin
    * 
    * @returns String recharging origin
    */
   public String getOrigin() {

      return origin;
   }

   /**
    * Returns task id
    * 
    * @returns int task id
    */
   public int getTaskId() {

      return taskId;
   }

   /**
    * Returns product id
    * 
    * @returns int product id
    */
   public int getProdId() {

      return prodId;
   }

   /**
    * Changes product batch number
    * 
    * @param pBatch
    *           String batch number
    */
   public void setQuantity(int pQty) {

      quantity = pQty;
   }

   /**
    * Returns recharging quantity
    * 
    * @returns int recharging quantity
    */
   public int getQuantity() {

      return quantity;
   }

   /**
    * Returns a copy of current instance
    * 
    * @return a cloned of this instance of Task
    */
   public Object clone() {

      Task l_new = new Task(description, code, prodId, taskId, batchNumber,
            quantity, origin, done);
      return l_new;
   }
}
